﻿using ReflectionStudio.Core.Events;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Data;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class VSDDAT
    {
        public void SetUpNewRow(ref DataRow dwReturn, string _SDSA)
        {
            #region
            #endregion
            dwReturn["SDSA"] = _SDSA;
            switch (_SDSA)
            {
                default:
                case "0012":
                case "0100":
                case "0109":
                case "0114":
                case "0015":
                case "0150":
                case "0168":
                case "0178":
                case "0181":
                case "0187":
                case "0192":
                case "0196":
                case "0201":
                case "0208":
                case "0209":
                case "0227":
                case "0241":
                case "0253":
                case "0255":
                case "0354":
                case "0433":
                case "0434":
                case "0435":
                case "0436":
                case "0437":              
                case "0561":
                case "0622":
                case "0706":
                case "0804":
                case "8884":
                case "8886":
                case "8887":
                case "8888":
                case "8883":
                    dwReturn["SDKEY"] = "001                    V";
                    dwReturn["SDDATEN"] = "A»Ò¡¢ºÚÉ«ÏµÁÐ£¨GY¡¢BK£©                            YB1       00000000456                                                               XKV     20150318        000000000000*";
                    break;
                case "0010":
                case "0041": 
                case "0149":
                case "0152":
                case "0224":
                case "0228":
                case "0231":
                case "0243":
                case "0245":
                case "0249":
                case "0252":
                case "0267":
                case "0275":
                case "0277":
                case "0352":
                case "0412":
                case "0413":
                case "0414":
                case "0424":
                case "0429":
                case "0450":
                case "0451":
                case "0453":
                case "0455":
                case "0457":
                case "0514":
                case "0458":
                case "0674":
                case "0676":
                case "0678":
                case "0680":
                case "0460":
                case "0477":
                case "0525":
                case "0665":
                case "0280":
                case "9158":
                case "9315":
                case "9316":
                case "9317":
                case "9318":
                case "9319":
                case "9324":
                case "9322":
                case "9320":
                case "9321":
                case "8872":
                case "8873":
                case "8874":
                case "8875":
                case "8876":
                case "8877":
                case "8878":
                case "8879":
                case "8880":
                case "8881":
                case "8882":
                case "8885":
                case "9200":
                case "9314":
                case "9343":
                case "9325":
                    dwReturn["SDKEY"] = "001                     ";
                    dwReturn["SDDATEN"] = "A»Ò¡¢ºÚÉ«ÏµÁÐ£¨GY¡¢BK£©                            YB1       00000000456                                                               XKV     20150318        000000000000*";
                    break;
            }
        }

        public DataRow Convert2SDDAT(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QuerySDDAT(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                case "JLT":
                default:
                    #region=========
                    dwReturn["SDSA"] = "0000";
                    dwReturn["SDKEY"] = "00000000                ";
                    dwReturn["SDDATEN"] = "A000000                                  0000000001000000    00000000                                                                  LIYJ    20141019        000000000000*";
                    #endregion
                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }

        public void MapSDDAT(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }

        public void SaveSDDAT(DataRow dwData, string ITXDBVERSION = "ITX", bool IsUpdate = true)
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;

            setResult = QuerySDDAT(dwData, 1);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapSDDAT(ref dwLocal, dwData);
            if (!flgExist)
            {
                InsertSDDAT(dwLocal);
            }
            if (IsUpdate)
            {
                UpdateSDDAT(dwLocal);
            }
        }

        public void InsertSDDAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {

            or1 = OracleDB.CreateCommand();
            or1.CommandText = "INSERT INTO SDDAT(SDSA,SDKEY,SDDATEN) VALUES (:SDSA:,:SDKEY:, :SDDATEN:)";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }

        public void DeleteSDDAT(DataRow dwData, int option = 1)
        {

            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    DSD01(dwData);
                    break; 
                default:
                    break;
            }
            Connect2Proxy(or1);
        }
        public void DSD01(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM SDDAT WHERE SDSA=:SDSA: AND SDKEY =:SDKEY:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }
        public void DSD00(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "DELETE FROM SDDAT WHERE SDSA=:SDSA:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);
        }

        public DataSet QuerySDDAT(DataRow dwData, int option = 1)
        {
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM SDDAT M WHERE ROWNUM<2";
                    break;
                case 1:
                    or1.CommandText = "SELECT * FROM SDDAT M WHERE SDSA=:SDSA: AND SDKEY =:SDKEY:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 12:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,4) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                    + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 13:
                    or1.CommandText = "SELECT M.*,SDSA,SUBSTR(SDKEY,3,6) AS KEY,SUBSTR(SDDATEN,2,40) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE  FROM SDDAT M WHERE SDSA=:SDSA: "
                        + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 14:
                    or1.CommandText = "SELECT SDSA,SUBSTR(SDKEY,3,10) AS KEY,SUBSTR(SDDATEN,2,40) AS DES,SUBSTR(SDDATEN,42,3) AS CR,SUBSTR(SDDATEN,45,3) AS CG,SUBSTR(SDDATEN,48,3) AS CB,SUBSTR(SDDATEN,42,9) AS CRGB,SUBSTR(SDDATEN,51,1) AS CGRP,SUBSTR(SDDATEN,52,10) AS SDES "
                      + " FROM SDDAT M WHERE SDSA=:SDSA: "
                         + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 15:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                case 22:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,8)AS AUFTYP,SUBSTR(SDKEY,11,2)AS KEY,SUBSTR(SDDATEN,74,2) AS DES,SUBSTR(SDDATEN,1,19) AS SDES,SUBSTR(SDDATEN,48,6) AS VALUE "
                     + " FROM SDDAT M WHERE SDSA=:SDSA:  "
                        + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 8885:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,8)AS AUFTYP,SUBSTR(SDKEY,11,2)AS KEY,SUBSTR(SDDATEN,74,2) AS DES,SUBSTR(SDDATEN,1,19) AS SDES,SUBSTR(SDDATEN,44,10) AS VALUE "
                      + " FROM SDDAT M WHERE SDSA=:SDSA:  "
                         + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 41:
                case 168:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString()
                           + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 109:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,15) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;

                case 114:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 149:
                    or1.CommandText = "SELECT M.*, CASE WHEN  SUBSTR(SDDATEN,45,7)= '       ' THEN  1 ELSE  SUBSTR(SDDATEN,45,7)*0.0001 END AS RATE,SUBSTR(SDKEY,3,3) AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,45,7) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString().Replace("V", "")
                           + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 150:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,45,7) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                           + dwData["SDKEY"].ToString()
                             + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 178:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3) AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 181:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,30) AS DES,SUBSTR(SDDATEN,40,12) AS VALUE,SUBSTR(SDDATEN,39,1) AS SDES  FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 187:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2)AS KEY,SUBSTR(SDDATEN,2,30) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 192:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN, 62, 8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString()
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 196:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,30) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 201:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 208:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,30) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 209:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 224:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,8) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString().Replace("V", "")
                           + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 228:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,8) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString().Replace("V", "")
                           + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 231:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,15)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString().Replace("V", "")
                           + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 241:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,30) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 243:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString().Replace("V", "");
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                case 245:
                case 249:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,20) AS VALUE,SUBSTR(SDDATEN,70,2) AS V1,SUBSTR(SDDATEN,72,2) AS V2,SUBSTR(SDDATEN,74,2) AS V3,SUBSTR(SDDATEN,76,2) AS V4 FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString().Replace("V", "")
                    + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;

                case 253:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 255:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,22) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 9314:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,20) AS VALUE,SUBSTR(SDDATEN,70,2) AS V1,SUBSTR(SDDATEN,72,2) AS V2,SUBSTR(SDDATEN,74,2) AS V3,SUBSTR(SDDATEN,76,2) AS V4 FROM SDDAT M "
                    + " WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 267:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,20) AS VALUE,SUBSTR(SDDATEN,70,2) AS V1,SUBSTR(SDDATEN,72,2) AS V2,SUBSTR(SDDATEN,74,2) AS V3,SUBSTR(SDDATEN,76,2) AS V4,SUBSTR(SDDATEN,78,2) AS V5 FROM SDDAT M "
                        +" WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString().Replace("V", "")
                    +" ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 280:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;

                case 352:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,10) AS KEY,SUBSTR(SDDATEN,2,50) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,60) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString();
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 100:
                case 433:
                case 434:
                case 435:
                case 436:
                case 437:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,30,1) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 354:
                case 622:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2)AS KEY,SUBSTR(SDDATEN,2,29) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                            + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 477:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,15) AS KEY,SUBSTR(SDDATEN,2,50) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 561:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1)AS KEY,SUBSTR(SDDATEN,2,20) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,70,5) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                            + dwData["SDKEY"].ToString()
                              + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
               
                case 277:
                case 414:
                case 429:
                case 804:
                case 9158:
                case 9315:
                case 9316:
                case 9317:
                case 9318:
                case 9319:
                case 9321:
                case 8874:
                case 8876:
                case 8877:
                case 8880:
                case 8881:
                case 8882: 
                case 9200:
                case 9320:
                case 9325:
                case 9343:
                    
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                 case 412:
                case 413:
                case 514:
                case 706:
                case 8872:
                case 8875:
                case 8878:
                case 8879:
                case 8884:
                case 9322: 
                case 9324:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 8886:
                
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,2) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString()
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                case 8883:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,8)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString()
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
               
                case 275:
                case 424:
                case 460:
                case 450:
                case 451:
                case 453:
                case 455:
                case 457:
                case 458:
                case 674:
                case 676:
                case 678:
                case 680:
                case 665:
                case 8873:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,3) AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                        + dwData["SDKEY"].ToString().Replace("V", "")
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;

                case 252:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,4)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                       + dwData["SDKEY"].ToString().Replace("V", "")
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                case 8887:
                case 8888:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,4)AS KEY,SUBSTR(SDDATEN,2,28) AS DES,SUBSTR(SDDATEN,52,10) AS SDES,SUBSTR(SDDATEN,62,8) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA:"
                         + dwData["SDKEY"].ToString()
                          + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break; 
                case 3:
                    or1.CommandText = "SELECT SDSA,SUBSTR(SDKEY,3,3) AS SDKEY,SUBSTR(SDDATEN,2,10) AS SDDATEN  FROM SDDAT WHERE SDSA=:SDSA:"
                       + dwData["SDKEY"].ToString()
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -1:
                    or1.CommandText = "SELECT M.*,SUBSTR(SDKEY,3,1) AS KEY,SUBSTR(SDDATEN,2,50) AS DES,SUBSTR(SDDATEN,51,10) AS SDES,SUBSTR(SDDATEN,69,5) AS VALUE FROM SDDAT M WHERE SDSA=:SDSA: "
                       + dwData["SDKEY"].ToString()
                        + " ORDER BY SDKEY";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -2:
                    or1.CommandText = "SELECT DISTINCT SDSA FROM SDDAT ORDER BY 1";
                    break;
                case -3:
                    or1.CommandText = "SELECT SDSA,SUBSTR(SDKEY,3,3) AS SDKEY,SUBSTR(SDDATEN,2,10) AS SDDATEN  FROM SDDAT WHERE SDSA=:SDSA:"
                        + " AND SDKEY LIKE '00" + dwData["SDKEY"].ToString() + "%'";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -4:
                    or1.CommandText = "SELECT MAX(KDKUNDNR) AS KUNDNR FROM KDSTAMM ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -5:
                    or1.CommandText = "SELECT MAX(VKKAUFLFD) AS VKAUFTR FROM VKKOPF WHERE VKKAUFKRS=:KEY: ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case -6:
                    or1.CommandText = "SELECT MAX(LSLIEFNR) AS LSLIEFNR FROM LIEFDAT ";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                case 9999:
                    or1.CommandText = "SELECT * FROM SDDAT WHERE SDSA=:SDSA:";
                    or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
                    break;
                default:
                    return Result;
                    break;
            }


            SResult = Connect2Proxy(or1);
            SResult.Tables[0].TableName = "SDDAT";
            return SResult;
        }
        
        public void UpdateSDDAT(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand(); 
            or1.CommandText = "UPDATE SDDAT SET SDDATEN=:SDDATEN: WHERE SDSA=:SDSA: AND SDKEY=:SDKEY:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData); 
            Connect2Proxy(or1);
        }
        //替换KEY
        public void USD03(DataRow dwData)
        {
            or1 = OracleDB.CreateCommand();
            or1.CommandText = "UPDATE SDDAT SET SDKEY=:SDDATEN: WHERE SDSA=:SDSA: AND SDKEY=:SDKEY:";
            or1.CommandText = INTEXDBC.InjectData(or1.CommandText, dwData);
            Connect2Proxy(or1);

        }
    }

}
